const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const { expressjwt: jwt } = require("express-jwt");
const config = require("./config/config.json");
const router = require("./router/router");
const signInRouter = require("./router/signInRouter");
const userRouter = require("./router/user");
const welfareGoodsRouter = require("./router/welfareGoodsRouter");
const otherRouter = require("./router/otherRouter");
const circleRouter = require("./router/circleRouter");
const pinRouter = require("./router/pinRouter");
const aiRouter = require("./router/aiRouter");
const settingRouter = require("./router/settingRouter");
const multer = require("multer");
const path = require("path");
const fs = require("fs");
const app = express();
app.use(bodyParser.json({ limit: "10mb", extended: true }));
let objMulter = multer({ dest: "./public/upload" });
//实例化multer，传递的参数对象，dest表示上传文件的存储路径
app.use(objMulter.any()); //any表示任意类型的文件
// app.use(objMulter.image())//仅允许上传图片类型
app.use(express.static("./public"));
app.use(bodyParser.json());
app.use(cors());

app.use("/api", router);
app.use("/api", signInRouter);
app.use("/api", userRouter);
app.use("/api", welfareGoodsRouter);
app.use("/api", otherRouter);
app.use("/api", circleRouter);
app.use("/api", pinRouter);
app.use("/api", aiRouter);
app.use("/api", settingRouter);

app.use(
  jwt({ secret: config.jwt.secret, algorithms: config.jwt.algorithms }).unless({
    path: [
      "/api/RegisterOrLogin",
      "/api/GetMenuTabs",
      "/api/GteArticleList",
      "/api/GetActivityList",
      "/api/sendCode",
    ],
  })
);

app.listen(6789, () => {
  console.log("6789端口监听中");
});
